<?php

/**
 * @content: 获取巡查项目列表，压缩成接送格式数据
 * @Author:  Groube
 * @Date:    2017-03-08 17:50:00
 * @version  $Id$
 */
class GetxunchaitemlistjsonController extends Yaf_Controller_Abstract {

    /**
     * @Title  禁用模板功能
     * @Author Groube
     * @Param  /
     * @Return /
     * @Date 2017/03/08 14:30
     */
    public function init() {
        $yiyuan_id = isset($_REQUEST['yiyuan_id']) ? $_REQUEST['yiyuan_id'] : "";

        if($yiyuan_id === "" ){
            Utility::apiJsonError(20028, '请输入医院ID');
        }elseif(!ctype_digit("$yiyuan_id")){
            Utility::apiJsonError(20027, '医院ID必须是整型');
        }

        Yaf_Dispatcher::getInstance()->disableView();
    }


    /**
     * @Title  入口方法
     * @Author Groube
     * @Param  /
     * @Return /
     * @Date 2017/03/08 18:00
     */
    function indexAction(){
        $request = $this->getRequest();
        $str_yiyuan_id = $request->getPost('yiyuan_id',0);
        $yiyuan_id = (int)$str_yiyuan_id;

        $data_xunchajilu_item_list = DB::select()->from('data_xunchajilu_item')
            ->where('yiyuan_id', '=', $yiyuan_id)
            ->where('is_include','=',1)
            ->execute()
            ->as_array();

        if(empty($data_xunchajilu_item_list)){
            Utility::apiJsonError(40014,'(Method:获取巡查项目列表，压缩成接送格式数据)巡查记录表中没有查到数据!');
        }

        $params_mod = new DataXunchajiluItemModel;
        $async_result = $params_mod->ls_item();

        if(!$async_result){
            $data = array('error'=>200,'msg'=>'暂无数据!','update_sql' => '');
            Utility::apiJsonResultExtends($data);
        }

        $field_arr = $params_mod->_field_arr;
        $async_result = Utility::formatToSqlStr($async_result,'data_xunchajilu_item','update_sql',$field_arr);
        $async_result['error'] = 200;
        $async_result['msg'] = '';
        Utility::apiJsonResultExtends($async_result);
    }
}